<?php
define('_file_','add_article');
if ( !isGod() )
	if ( !getRights($mod,'full') )
		if ( !News_getAccessFile(_file_) )
		{
			showMsg('Không có quyền truy cập vào trang này này !','ex','center');
			die();
		}
	$tid = getVar('hidTid',true,true);

	$title = getVar('txtTitle',false,true);
	$scontent = getVar('txtSContent',false,true);
	$fcontent = getVar('txtFContent',false,true);

	$title1 = getVar('txtTitle1',false,true);
	$scontent1 = getVar('txtSContent1',false,true);
	$fcontent1 = getVar('txtFContent1',false,true);

	$datepost = getVar('txtDatePost',false,true);
	
	$username = $_SESSION['sesusername'];

	$datepost = date('Y-m-d');

	$imgid = 0;

	/*******************************************************************************/	
	//neu co anh -> insert vao db anh
	//qui trinh: upload anh len thu muc tam tren server -> ghi vao db -> xoa anh trong thu muc tam
	$upload_dir = 'temp/';

	$max_file_upload=return_bytes(ini_get('post_max_size'));

	if($_FILES['filPicture']['size'] > 0 )
	{
		$upload_file=$upload_dir.basename($_FILES['filPicture']['name']);

		if(file_exists($_FILES['filPicture']['name']))
		{
			$temp=explode(basename($_FILES['filPicture']['name']));
			$temp[0].=substr(rand(0,1000),0,2);	
		}

		$extension=strtolower(strrchr($upload_file,"."));

		if(empty($arr_extension[$extension]))
			die('KhÃ´ng Ä‘Ãºng pháº§n má»Ÿ rá»™ng !');

		if(filesize($_FILES['filPicture']['tmp_name'])< $max_file_upload)
		{	
			if(is_uploaded_file($_FILES['filPicture']['tmp_name']))
			{
die($upload_file . '<br />' . $_FILES['filPicture']['tmp_name']);
				if( !move_uploaded_file($_FILES['filPicture']['tmp_name'],$upload_file) )
					die('Upload khÃ´ng thÃ nh !');
				else
				{
					$imgid = InsertImgToDB('temp/',basename($_FILES['filPicture']['name']));
					//xoa anh
					unlink($upload_file);
				}
			}
			else 
				die('KhÃ´ng copy vÃ o thÆ° má»¥c táº¡m Ä‘Æ°á»£c !');
		}
		else
			die('KÃ­ch thÆ°á»›c file quÃ¡ lá»›n !');
	}
	/*******************************************************************************/
	$sql = "INSERT INTO article(tid,title_vn,title_en,short_content_vn,short_content_en,full_content_vn,full_content_en,picture,datepost,username) VALUES(";
	$sql .= "$tid,'$title','$title1','$scontent','$scontent1','$fcontent','$fcontent1',$imgid,'$datepost','$username')";

	$link->execute($sql);
		
showMsg('Đã cập nhật thành công.<br />
Vui lòng chờ trong giây lát...
<meta http-equiv="refresh" content="1;URL='.$mod.'&act=view_topic&cid=1" />
','info','center');die();
?>